#include <stdio.h>

#define STUDENTS 10
#define COURSES 5

// 函数：计算每个学生的平均分
void calculateStudentAverages(int grades[STUDENTS][COURSES]) {
    printf("student averages\n");
    for (int i = 0; i < STUDENTS; i++) {
        int sum = 0;
        for (int j = 0; j < COURSES; j++) {
            sum += grades[i][j];
        }
        printf("student:%d avg:%.2f\n", i + 1, sum / (float)COURSES);
    }
}

// 函数：计算每门课的平均分
void calculateCourseAverages(int grades[STUDENTS][COURSES]) {
    printf("\ncourse averages\n");
    for (int j = 0; j < COURSES; j++) {
        int sum = 0;
        for (int i = 0; i < STUDENTS; i++) {
            sum += grades[i][j];
        }
        printf("course:%d avg:%.2f\n", j + 1, sum / (float)STUDENTS);
    }
}

// 函数：找出所有分数中的最高分，并输出对应的学生和课程
void findHighestScore(int grades[STUDENTS][COURSES]) {
    int maxScore = -1;
    int maxStudent = -1;
    int maxCourse = -1;

    // 遍历所有成绩，找出最大成绩及其对应的学生和课程
    for (int i = 0; i < STUDENTS; i++) {
        for (int j = 0; j < COURSES; j++) {
            if (grades[i][j] > maxScore) {
                maxScore = grades[i][j];
                maxStudent = i;
                maxCourse = j;
            }
        }
    }

    // 输出结果
    printf("\nhighest score:%d, from student:%d course:%d\n", 
        maxScore, maxStudent + 1, maxCourse + 1);
}

int main() {
    int grades[STUDENTS][COURSES];

    // 输入学生成绩
    printf("input 10 students 5 courses:\n");
    for (int i = 0; i < STUDENTS; i++) {
        for (int j = 0; j < COURSES; j++) {
            printf("student:%d course:%d score: ", i + 1, j + 1);
            scanf("%d", &grades[i][j]);
        }
    }

    // 调用函数计算和输出
    calculateStudentAverages(grades);
    calculateCourseAverages(grades);
    findHighestScore(grades);

    return 0;
}
